package com.tidc.seaquartz.config;

import com.tidc.seaquartz.job.ClearRabbit;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * @author ：冯涛滔
 * @date ：Created in 2020/10/5 9:53
 * @description：
 * @modified By：
 * @version:
 */
@Configuration
public class QuartzConfig {
    @Resource
    private Scheduler scheduler;
    @Bean
    public JobDetail jobDetail() {
        JobDetail jobDetail = JobBuilder.newJob(ClearRabbit.class)
                .withIdentity("ClearRabbit", "ClearRabbitGroup")
                .storeDurably()
                .build();
        return jobDetail;
    }

    @Bean
    public Trigger trigger() {
        Trigger trigger = TriggerBuilder.newTrigger().withIdentity("ClearRabbitTrigger", "ClearRabbitTriggerGroup")
                .forJob(jobDetail())
                .startNow()//立即生效
                .withSchedule(SimpleScheduleBuilder.simpleSchedule()
                        .withIntervalInSeconds(600)//每隔60s执行一次
                        .repeatForever()).build();//一直执行
        return trigger;
    }
}